home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / brklyprl.lha / Emulator / inst_args.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-14  |  3.3 KB  |  156 lines

  1.  
  2. /* Copyright (C) 1988, 1989 Herve' Touati, Aquarius Project, UC Berkeley */
  3.  
  4. /* Copyright Herve' Touati, Aquarius Project, UC Berkeley */
  5.  
  6. enum {
  7.   UNRESOLVED_ADDRESSES,
  8.   NO_UNRESOLVED_ADDRESSES
  9.   };
  10.  
  11. class InstrArg {
  12.  public:
  13.   char* name;
  14.   HashTable* TableOfTables;
  15.   int status;
  16.   virtual void init(Scan& scanner) {}
  17.   virtual int fill(char*) {return 0;}
  18.   virtual void print(int value) {cout << value;}
  19.   virtual void clear() {}
  20.   virtual void define(int, int) {}
  21.   virtual int update(int) {return -1;}
  22.   virtual int get_arity(int) {return -1;}
  23.   virtual void print_proc_table() {}
  24.   virtual PF get_exec(int) {return 0;}
  25.   virtual HashTable* get_table() {return 0;}
  26. };
  27.  
  28. class NoArg : public InstrArg {
  29.  public:
  30.   void print(int value) {}
  31. };
  32.  
  33. enum {XVAR, YVAR};
  34. /* Xi<->i-1, Yi<->i-1 */
  35. class Var : public InstrArg {
  36.  public:
  37.   int fill(char* s);
  38. };
  39.  
  40. class Atom : public InstrArg {
  41.   static StringTable* symbol_table;
  42. public:
  43.   void init(Scan& ST) {symbol_table = &ST;}
  44.   int fill(char* s) {
  45.     Cell atom = make_atom(symbol_table->intern(s));
  46.     return atom;
  47.   }
  48.   void print(int value) {
  49.     cout << (char*) get_string(value);
  50.   }
  51. };
  52.  
  53. class Table : public InstrArg {
  54.   static Scan* scanner;
  55.   static int tcdr;
  56.   static int table_count;
  57.  public:
  58.   void init(Scan& SC) {
  59.     scanner = &SC;
  60.     tcdr = scanner->intern("tcdr");
  61.     TableOfTables = new HashTable;
  62.   }
  63.   int fill(char* s);
  64.   void print(int value);
  65. };
  66.  
  67. class Int : public InstrArg {
  68.  public:
  69.   int fill(char* s);
  70.   void print(int value) {cout << value;}
  71. };
  72.  
  73. enum {
  74. #define NAMES
  75. #define use(ID,name,Function)\
  76.   ID,
  77. #include "built_ins.h"
  78. #undef use
  79. #undef NAMES
  80. LAST_BUILT_IN
  81. };
  82.  
  83. struct BuiltInEntry {
  84.   int name;
  85.   PF exec;
  86. };
  87.  
  88. class BuiltIn : public InstrArg {
  89.  public:
  90.   static HashTable* name_to_ID;
  91.   static HashTable* exec_to_ID;
  92.   static BuiltInEntry* built_in_table;
  93.   static StringTable* symbol_table;
  94.   void init(Scan& ST);
  95.   PF get_exec(int name);
  96.   int fill(char* s) {
  97.     int ID = name_to_ID->get(symbol_table->intern(s));
  98.     return (int) built_in_table[ID].exec;
  99.   }
  100.   void print(int value) {
  101.     int ID = exec_to_ID->get(value);
  102.     int name = built_in_table[ID].name;
  103.     printf("%d:%s", ID, name);
  104.   }
  105. };
  106.  
  107. class Const : public InstrArg {
  108.   static StringTable* symbol_table;
  109.  public:
  110.   void init(Scan& ST) {symbol_table = &ST;}
  111.   int fill(char* s);
  112.   void print(int value);
  113. };
  114.  
  115. class Label : public InstrArg {
  116.   static HashTable* label_table;
  117.  public:
  118.   void define(int label, int address) {label_table->bind(label, address);}
  119.   int update(int label);
  120.   void clear() {label_table->clear();}
  121.   void init(Scan&);
  122.   int fill(char* s);
  123.   void print(int label);
  124. };
  125.  
  126. class Proc : public InstrArg {
  127.   static HashTable* proc_addr_table;
  128.   static StringTable* symbol_table;
  129.   static HashTable* proc_name_table;
  130.  public:
  131.   void init(Scan& ST);
  132.   int fill(char* s) {return symbol_table->intern(s);}
  133.   HashTable* get_table();
  134.   void define(int name, int address) {
  135.     proc_addr_table->bind(name, address);
  136.     proc_name_table->bind(address, name);
  137.   }
  138.   int update(int name);
  139.   int get_arity(int address);
  140.   void print(int address);
  141.   void print_proc_table();
  142. };
  143.  
  144. enum {
  145. #define use(String,ARGID,Name)\
  146.   ARGID,
  147. #include "list_inst_args.h"
  148. #undef use
  149.   ARG_LAST
  150.   };
  151.  
  152. extern InstrArg* instr_args[];
  153. extern void init_instr_args(Scan& scanner);
  154.  
  155. const int LABEL_FAIL = -1;
  156.